package com.yunhai.support.config;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
import darabonba.core.client.ClientOverrideConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

@Configuration
public class AliMessageConfig {

    private static String ACCESS_KEY_ID = "LTAI4Fd51KuU7a69o7trPRhC";
    private static String ACCESS_KEY_SECRET = "3M9AgooM0xH0RmWOrqggHsKU0nBNFr";
    private static String REGION = "cn-beijing";

    @Bean(value="aliMessageClient")
    public AsyncClient client(){
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                .accessKeyId(ACCESS_KEY_ID)
                .accessKeySecret(ACCESS_KEY_SECRET)
                .build());

        return  AsyncClient.builder()
                .region(REGION) // Region ID
                .credentialsProvider(provider)
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                .setEndpointOverride("dysmsapi.aliyuncs.com")
                        .setConnectTimeout(Duration.ofSeconds(15))
                )
                .build();
    }

}
